package com.demo.morning;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * @ClassName Reflect
 * @Description TODO
 * @Author tianqinglong
 * @Date 11:40 2022/7/12
 * @Version 1.0
 **/
public class Reflect {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException {
        反射();
    }

    private static void 反射() throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException {
        Class<A> aClass = (Class<A>) Class.forName("com.demo.morning.A");
        Class<A> aClass1 = A.class;
        Class<? extends A> aClass2 = new A().getClass();
        System.out.println(aClass==aClass1);
        System.out.println(aClass==aClass2);
        Method[] methods = aClass.getMethods();
        for (Method method : methods) {
            System.out.println(method);
        }
//        Field field = aClass.getDeclaredField("b");
//        Field modifiers = Field.class.getDeclaredField("b");
//        field.setAccessible(true);
//        modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
//        field.set(field,20);
//        System.out.println(field.get(field));

    }
}
class A{
private int a;
public  int b;

    public int getA() {
        return a;
    }

    public void setA(int a) {
        this.a = a;
    }

    public int getB() {
        return b;
    }

    public void setB(int b) {
        this.b = b;
    }

    public void show(){
    System.out.println("被你发现了");
}
}
